package org.dreamwork.peony;

import java.lang.reflect.Method;

/**
 * Created by IntelliJ IDEA.
 * User: seth
 * Date: 2009-8-18
 * Time: 18:02:06
 */
public class ExpressionRunner {
    private Object object;
    private Class claxx;

    public ExpressionRunner (Object object) {
        this.object = object;
        claxx = object.getClass ();
    }

    public Object eval (String expression, Object[] args, Class<?>... types) throws Exception {
        Method method = claxx.getMethod (expression, types);
        if (method != null)
            return method.invoke (object, args);
        return null;
    }

    public Object eval (String expression) throws Exception {
        Method method = claxx.getMethod (expression);
        if (method != null)
            return method.invoke (object);
        return null;
    }
}